/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.
 */
package es.silenus.detecta.dao.impl;

import es.silenus.detecta.dao.CouncilDAO;

import es.silenus.detecta.model.Council;

import org.hibernate.Session;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * DOCUMENT ME!
 *
 * @author <a href="mailto:dgarcia@silenus-consultoria.es">Daniel Garc&iacute;a</a>
 *
 * @since 02-abr-2009 12:15:37
 */
public class CouncilDAOImpl extends ReadDAOImpl<Council, String> implements CouncilDAO {
	/**
	 * Finds councils given a province.
	 *
	 * @param provinceId the province id.
	 *
	 * @return the list of councils.
	 */
	@SuppressWarnings("unchecked")
	@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
	public List<Council> findByProvince(String provinceId) {
		Session session = null;

		try {
			session = getSession();

			return session.getNamedQuery(Council.class.getName() + ".findByProvince").setString("province", provinceId).list();
		} finally {
			releaseSession(session);
		}
	}
}
